package com.csun.cmny.provider.dao;

import com.csun.cmny.provider.model.domain.DmcDeviceAlert;
import com.csun.cmny.provider.model.dto.DeviceAlertDto;
import com.csun.cmny.provider.model.dto.alert.DeviceAlertPageQuery;
import com.csun.cmny.provider.model.dto.life.DeviceAlertLifeByIosSelectDto;
import com.csun.cmny.provider.model.vo.DeviceAlertReqVo;
import com.csun.cmny.provider.model.vo.DeviceReqVo;
import com.csun.cmny.provider.model.vo.SleepAlertByHour;
import com.csun.cmny.provider.model.vo.csunsleep.DmcCsunSleepVo;
import com.csun.cmny.provider.model.vo.device.DmcDeviceAlertLifeRoomVo;
import com.csun.cmny.provider.model.vo.device.DmcDeviceAlertLifeVo;
import com.csun.cmny.provider.model.vo.device.DmcDeviceAlertVo;
import org.apache.ibatis.annotations.Param;
import tk.mybatis.mapper.common.Mapper;

import java.util.Date;
import java.util.List;
import java.util.Map;

public interface DmcDeviceAlertMapper extends Mapper<DmcDeviceAlert> {

    /**
     * query device alert list with page
     *
     * @param deviceAlertPageQuery  device alert page quert
     *
     * @return  the list.
     */
    List<DmcDeviceAlertVo> queryDeviceAlertListWithPage(DeviceAlertPageQuery deviceAlertPageQuery);

    /**
     * batch delete by id list
     *
     * @param idList  delete id list
     *
     * @return  the int.
     */
    Integer batchDeleteByIdList(@Param("idList") List<Long> idList);

    /**
     * batch read by id list
     *
     * @param map    map
     *
     * @return  the int.
     */
    Integer batchReadByIdList(Map<String, Object> map);

    /**
     * query device alert by building id and floor no
     *
     * @param deviceReqVoList device req vo list
     *
     * @return
     */
    List<DmcDeviceAlertVo> queryDeviceAlertByBuildingIdAndFloorNo(@Param("deviceReqVoList") List<DeviceReqVo> deviceReqVoList);

    /**
     * update device alert play times by id
     *
     * @param id    device alert id
     *
     * @return  the int.
     */
    Integer updateDeviceAlertPlayTimesById(Long id);

    /**
     * query device alert list by id list
     *
     * @param idList    id list
     *
     * @return  the list.
     */
    List<DmcDeviceAlert> queryDeviceAlertListByIds(@Param("idList") List<Long> idList);

    /**
     * query device alert by device list
     *
     * @param deviceReqVoList device req vo list
     *
     * @return the list
     */
    List<DeviceAlertReqVo> queryDeviceAlertByDeviceList(@Param("deviceReqVoList") List<DeviceReqVo> deviceReqVoList);

    /**
     * 批量更新
     *
     * @param idList
     * @param dmcDeviceAlert
     *
     * @return
     */
    Integer batchUpdate(@Param("idList") List<Long> idList, @Param("dmcDeviceAlert") DmcDeviceAlert dmcDeviceAlert);

    /*
    * 根据老人id集合和日期查询报警信息
    * */
    List<DeviceAlertReqVo> queryDeviceAlertByOldIdAndDate(DeviceAlertReqVo deviceAlertQuery);

    /**
     * 通过设备id和起止时间查询报警次数
     * @param: [deviceAlertPageQuery]
     * @return: java.lang.Integer
     */
    Integer countAlertTimesByTypeAndTime(DeviceAlertPageQuery deviceAlertPageQuery);

    /**
     * 根据老人id查询报警信息
     * @param oldmanId
     * @return
     */
    List<DmcDeviceAlertVo> queryDeviceAlertByOldId(Integer oldmanId);


    /**
     * 查询机构下所有报警信息
     * @param groupId
     * @return
     */
    List<DmcDeviceAlertLifeVo> queryDeviceAlertLife(Long groupId);

    /**
     *查询房间内的所有报警信息
     * @param deviceIds
     * @param groupId
     * @return
     */
    List<DmcDeviceAlertLifeRoomVo> queryDeviceAlertLifeRoom(@Param("deviceIds") List<Long> deviceIds,@Param("groupId") Long groupId);


    /**
     * 处理报警信息
     * @param alertId
     * @param loginName
     * @return
     */
    Integer updateAlert(@Param("alertId") Long alertId, @Param("loginName") String loginName,@Param("updateTime") Date updateTime);

    /**
     * 根据房间id查询报警数据
     * @param id
     * @return
     */
    List<DmcDeviceAlert> selectAlertDataByRoomId(@Param("id") Long id,@Param("groupId") Long groupId);

    /**
     * 查询房间下指定时间段的报警信息
     * @param deviceIds
     * @param groupId
     * @param startTime
     * @param endTime
     * @return
     */
    List<DmcDeviceAlertLifeRoomVo> queryDeviceAlertLifeRoomAndTime(@Param("deviceIds") List<Long> deviceIds,@Param("groupId") Long groupId,@Param("startTime") Date startTime,@Param("endTime") Date endTime);

    /**
     *
     * @param alertIds
     * @param groupId
     * @return
     */
    List<DmcDeviceAlertLifeVo> selectColor(@Param("alertIds") List<Long> alertIds, @Param("groupId") Long groupId);

    /**
     *
     * @param deviceAlertPageQuery
     * @return
     */
    List<DmcDeviceAlertLifeRoomVo> queryDeviceAlertLifeRoomIndex(DeviceAlertPageQuery deviceAlertPageQuery);

    Integer updateAlerts(@Param("alertIds") List<Long> alertIds, @Param("loginName") String loginName,@Param("updateTime") Date updateTime);

    Long saveAlert(DmcDeviceAlert deviceAlertDto);

    List<DmcDeviceAlertLifeVo> queryDeviceAlertLifeByIos(DeviceAlertLifeByIosSelectDto deviceAlertLifeByIosSelectDto);
    //查询该设备最新报警时间
    List<DmcDeviceAlertVo> queryDeviceAlert(DeviceAlertPageQuery deviceAlertPageQuery);
    /**
     * 守护佳床垫报警按时间分布
     * @return Wrapper
     */
    SleepAlertByHour selectSleepAlertByhour(Long groupId);
    //查询床垫报警
    List<com.csun.cmny.provider.model.vo.DmcDeviceAlert> queryDeviceAlertBySleep(@Param("dmcCsunSleepVos") List<DmcCsunSleepVo> dmcCsunSleepVos);
}